﻿using System;
using System.Windows.Forms;

using Moe.ECamel.Client.WinForms.Common;

namespace Moe.ECamel.Client.WinForms.Forms
{
	public partial class DatePickerForm : ECamelForm
	{
		public static DateTime? ShowSelectSingleDateDialog(DateTime initialDate, DateTime? minDate, DateTime? maxDate)
		{
			using (var form = new DatePickerForm())
			{
				if (minDate != null)
					form.monthCalendar1.MinDate = minDate.Value;
				if (maxDate != null)
					form.monthCalendar1.MaxDate = maxDate.Value;

				form.monthCalendar1.MaxSelectionCount = 1;
				form.monthCalendar1.SelectionStart = initialDate;

				var dialogResult = form.ShowDialog();
				if (dialogResult == DialogResult.Cancel)
					return null;

				return form.monthCalendar1.SelectionStart;
			}
		}

		public DatePickerForm()
		{
			InitializeComponent();
		}

		private void CancellationButton_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
		private void ConfirmationButton_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.OK;
			this.Close();
		}
	}
}
